<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html>
<html class="x-admin-sm">
    
    <head>
    	<base href="<%=basePath%>">
        <meta charset="UTF-8">
        <title>欢迎页面-X-admin2.2</title>
        <meta name="renderer" content="webkit">
	    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <link rel="stylesheet" href="<%=basePath %>leyuiyc/css/font.css">
        <link rel="stylesheet" href="<%=basePath %>leyuiyc/css/xadmin.css">
        <script type="text/javascript" src="<%=basePath %>leyuiyc/lib/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="<%=basePath %>leyuiyc/js/xadmin.js"></script>
        <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
        <!--[if lt IE 9]>
            <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
            <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->
    </head>
<body>
	<div class="layui-fluid">
		<div class="layui-row layui-col-space15">
			<div class="layui-col-md12">
				<div class="layui-card">
					<div class="layui-card-body ">
						<table class="layui-table layui-form" id="test" lay-filter="test">
						</table>
						<input class="fileupload-input" id="userId" type="hidden" name="picpath" value="${userinfo.userId }"/>
						<input class="fileupload-input" id="userName" type="hidden" name="picpath" value="${userinfo.userName }"/>
						<input class="fileupload-input" id="supplierName" type="hidden" name="picpath" value="${supplierName }"/>
					</div>
				</div>
			</div>
		</div>
	</div>
<script type="text/html" id="switchTpl">
  <!-- 这里的 checked 的状态只是演示 -->
<div class="layui-input-inline">
      <input type="text" name="titl" id="num" class="layui-input" value="{{d.num == null ? "":d.num}}" disabled="disabled">
</div>
</script>
	<script>
				layui.use(['table','form','slider','layedit', 'laydate', "jquery"], function(){
				  var form = layui.form
				  ,layer = layui.layer
				  ,layedit = layui.layedit
				  ,laydate = layui.laydate
				  ,slider = layui.slider
				  ,table = layui.table
				  ,$ = layui.jquery;
				  var text = ${brandId};
				  var storage = window.sessionStorage;
				  var aaa =  storage.getItem("num");
				  var bbb =  storage.getItem("goodsCommonId");
				  var ar =  storage.getItem("ar");
				  var ar2 =  storage.getItem("ar2");
				  var ar3 =  storage.getItem("ar3");
				  var service_point_id = storage.getItem("service_point_id");
				  var goodsCommonId = Number(bbb);
				  var supplierName = $("#supplierName").val();
				  var userId = $("#userId").val();
				  var userName = $("#userName").val();
				  console.log("ar"+ar);
				  console.log("ar2"+ar2);
				  console.log("ar3"+ar3);
				  table.render({
				    elem: '#test'
				    ,url:'purchasing/selectCommonGoodsHeart.do?brandId='+text+'&num='+aaa+'&goodsCommonId='+goodsCommonId
				    ,width: 'auto'
				    ,anim: 2
				    ,height: 400
				    ,method: 'post'
				    ,title: '订单信息表'
				    ,page: true
				    ,cols: [[
			    	   {field:'goodsCommonId', width:80, title: '商品id',align:'center'}
				      ,{field:'goodsName', width:150, title: '商品名称',align:'center'}
				      ,{field:'specifications', width:150, title: '商品规格',align:'center'}
				      ,{field:'shippingFee', width:130, title: '销售价格',align:'center'}
				      ,{field:'num', width:200, title: '采购数量',templet:'#switchTpl', unresize: true}
				      ,{field:'', width:260, title: '操作',toolbar:'#operation',align:'center'}
				    ]]
				    ,skin: 'row' //表格风格
	                ,limits:[10,20,30,40,50]
				    ,limit: 20 //每页默认显示的数量
				  });
				  storage.removeItem('num');
				  storage.removeItem('ar');
				  storage.removeItem('ar2');
				  storage.removeItem('ar3');
				  storage.removeItem('goodsCommonId');
				  storage.removeItem('service_point_id');
 				 /* 操作框操作 */
    		table.on('tool(test)', function(obj) {
    			var data = obj.data;
    			var goodsName = data.goodsName;
    			var goodsCommonId = data.goodsCommonId;
    			var num = data.num;
    			var purchaseGoodsId = new Date().getTime();//采购单编号
    			var number = data.num;
    			console.log("number"+number);
    			var specifications = data.specifications;
    			if (obj.event === 'modify'){
    				var url = "purchasing/goAddTvPurchase3.do?goodsName="+goodsName+"&goodsCommonId="+goodsCommonId;
    				layer.open({
    					type : 2,
    					title : '库存信息',
    					maxmin : true,
    					area : [ '950px', '580px' ], //弹出框大小
    					content : url,
    					end : function() {}
    				});
	    			}else if(obj.event === 'add'){
	    			if(num>0){
	    				$.ajax({
	                    	url:"purchasing/addTvPurchase.do",
	                    	type:"post",
	                    	dataType:"json",
	                    	data:{
	                    	"supplierId":text
	                    	,"supplierName":supplierName
	                    	,"userId":userId
	                    	,"userName":userName
	                    	,"purchaseId":purchaseGoodsId
	                    	},	                    	
	                    	success:function(data){
	                    		if(data != null){
	                    			$.ajax({
				                    	url:"purchasing/addTvPurchaseDetails.do",
				                    	method:"post",
				                    	dataType:"json",
				                    	data:{
				                    	"goodsId":goodsCommonId
				                    	,"goodsName":goodsName
				                    	,"number":number
				                    	,"specifications":specifications
				                    	,"servicePointId":service_point_id
				                    	,"purchaseId":purchaseGoodsId
				                    	,"ar":ar
				                    	,"ar2":ar2
				                    	,"ar3":ar3
				                    	},
				                    	success:function(data){
				                    		if(data > 0){
				                    			layer.msg('添加成功', {icon: 1,time: 1000},function(){
				                    				var index = parent.layer.getFrameIndex(window.name);  
													parent.layer.close(index);
				                    			});
				                    			
				                    			return;
				                    		}
				                    		return;
				                    	}
				                    })
	                    			return;
	                    		}
	                    		
	                    		return;
	                    	}
	                    	
	                    })
	    			}else{
	    				layer.msg('请确定是否添加采购数量', {
    									icon : 2
    								});
	    			}
	    				
    			}
    			
    		});
    		
		 });
				</script>
	<script type="text/html" id="operation">
		       <a lay-event="modify"><button class="layui-btn layui-btn-normal" ><i class="layui-icon">&#xe6b2;</i>更改采购数量</button></a>	
               <a lay-event="add"><button class="layui-btn" >保存采购单</button></a>
 	</script>
	<script type="text/html" id="toolbarDemo">
   					 
				</script>
</body>

</html>
